package com.sinoeyes.controller.system;


import com.sinoeyes.auth.core.util.SecurityUtils;
import com.sinoeyes.common.core.controller.BaseController;
import com.sinoeyes.common.core.page.RestPageResult;
import com.sinoeyes.common.result.Result;
import com.sinoeyes.framework.aspectj.lang.annotation.Log;
import com.sinoeyes.framework.aspectj.lang.enums.BusinessType;
import com.sinoeyes.system.filter.SysNoticeFilter;
import com.sinoeyes.system.service.ISysNoticeService;
import com.sinoeyes.system.vo.SysNoticeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 公告 信息操作处理
 *
 */
@RestController
@RequestMapping("/system/notice")
@Api(value = "公告 信息操作处理 API", tags = {"公告 信息操作处理"})
public class SysNoticeController extends BaseController
{
    @Autowired
    private ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:notice:list')")
    @GetMapping("/list")
    @ApiOperation("获取通知公告列表")
    public Result<RestPageResult<SysNoticeVo>> list(SysNoticeFilter noticeFilter) {
        RestPageResult<SysNoticeVo> pageResult = noticeService.selectNoticeList(noticeFilter);
        return Result.success(pageResult);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = "/{noticeId}")
    @ApiOperation("根据通知公告编号获取详细信息")
    public Result<SysNoticeVo> getInfo(@PathVariable Long noticeId)
    {
        return Result.success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增通知公告")
    public Result<Integer> add(@RequestBody SysNoticeVo notice)
    {
        notice.setCreateBy(SecurityUtils.getUsername());
        return Result.success(noticeService.insertNotice(notice));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改通知公告")
    public Result<Integer> edit(@RequestBody SysNoticeVo notice)
    {
        notice.setUpdateBy(SecurityUtils.getUsername());
        return Result.success(noticeService.updateNotice(notice));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeId}")
    @ApiOperation("删除通知公告")
    public Result<Integer> remove(@PathVariable Long noticeId)
    {
        return Result.success(noticeService.deleteNoticeById(noticeId));
    }
}
